<template>
  <div class="qn-video-history-item">
    <div v-if="videoSrc == ''" class="no-video">
      请选择回放视频
    </div>
    <video-player
      v-else
      class="vjs-custom-skin"
      :options="playerOptions"
      :playsinline="true"
      @ready="changePlayerBtn">
    </video-player>
  </div>
</template>
<script>
import videojs from 'video.js'
import 'video.js/dist/video-js.css'
import 'vue-video-player/src/custom-theme.css'
import { videoPlayer } from 'vue-video-player'
import 'videojs-contrib-hls'

export default {
  components: {
    videoPlayer
  },
  data() {
    return {
      playerOptions: {
        autoplay: true,
        muted: true,
        // fluid: true, // 自适应容器大小
        notSupportedMessage: '此视频暂无法播放，请稍后再试',
        controls: true,
        controlBar: {
          timeDivider: true,
          durationDisplay: true,
          remainingTimeDisplay: false,
          fullscreenToggle: true // 全屏按钮
        },
        flash: {
          hls: {
            withCredentials: false
          }
        },
        html5: {
          hls: {
            withCredentials: false
          }
        },
        sources: [{
          withCredentials: false,
          type: 'application/x-mpegURL',
          src: ''
        }]
      },
      videoSrc: '',
      videoTitle: '',
      videoId: ''
    }
  },
  methods: {
    changePlayerBtn(player) {
      // this.addCloseBtn(player)
      // this.addShotBtn(player)
      // this.addVideoTitle(player)
    },
    addCloseBtn(player) {
      const _this = this
      const closeBtn = player.controlBar.addChild('button')
      closeBtn.addClass('el-icon-close')
      closeBtn.addClass('vjs-control')
      closeBtn.addClass('vjs-button')
      closeBtn.addClass('vjs-close-control')
      closeBtn.on('click', () => {
        _this.$emit('closeVideo')
      })
    },
    addShotBtn(player) {
      const _this = this
      const shotBtn = player.controlBar.addChild('button')
      shotBtn.addClass('iconfont')
      shotBtn.addClass('icon-shot')
      shotBtn.addClass('vjs-control')
      shotBtn.addClass('vjs-button')
      shotBtn.addClass('vjs-shot-control')
      shotBtn.on('click', () => {
        _this.$emit('shotVideo', player.currentTime())
      })
    },
    addVideoTitle(player) {
      const _this = this
      const titleDiv = player.controlBar.addChild('button')
      titleDiv.addClass('vjs-video-title')
      videojs.dom.appendContent(titleDiv.el_, _this.videoTitle)
    }
  },
  mounted() {
  }
}
</script>

<style lang="scss">
  .qn-video-history-item {
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    overflow: hidden;
    &.select {
      border: 2px solid $color-danger;
    }
    .video-player {
      width: 100%;
      height: 100%;
    }
    .video-js {
      height: 100%;
      outline: none !important;
      &.vjs-playing .vjs-tech {
        pointer-events: none;
      }
      .vjs-big-play-button {
        // 播放按钮换成圆形
        height: 2em;
        width: 2em;
        line-height: 2em;
        border-radius: 1em;
      }
      .vjs-control:focus {
        outline: none !important;
      }
      .vjs-control-bar {
        /*top: 0;*/
        /*height: 28px;*/
        /*.vjs-button > .vjs-icon-placeholder:before {*/
          /*line-height: 1;*/
          /*font-size: 22px;*/
        /*}*/
        /*.vjs-play-control {*/
          /*display: none;*/
        /*}*/
        /*.vjs-current-time {*/
          /*display: none;*/
        /*}*/
        /*.vjs-time-divider {*/
          /*display: none;*/
        /*}*/
        /*.vjs-time-control {*/
          /*display: none !important;*/
        /*}*/
        /*.vjs-progress-control {*/
          /*visibility: hidden;*/
        /*}*/
        /*.vjs-fullscreen-control {*/
          /*margin-right: 25px;*/
          /*margin-top: 2px;*/
        /*}*/
        /*.vjs-volume-panel {*/
          /*position: absolute;*/
          /*right: 62px;*/
          /*top: 2px;*/
          /*.vjs-volume-bar {*/
            /*margin: 0.7em 0.45em;*/
          /*}*/
        /*}*/
        .vjs-close-control {
          position: absolute;
          right: 0;
          font-weight: bold;
          font-size: 20px;
          width: 42px;
          cursor: pointer;
        }
      }
      .vjs-error-display {
        background: #000;
        &:before {
          content: ''
        }
        .vjs-modal-dialog-content {
          display: flex;
          align-items: center;
          justify-content: center;
        }
      }
    }
    .no-video {
      background: #000;
      color: #fff;
      height: 100%;
      display: flex;
      align-items: center;
      justify-content: center;
    }
  }
</style>
